package com.easyj.base.common.page;

import java.io.Serializable;
import java.util.List;

public class Page<T> implements Serializable {
	
	private static final long serialVersionUID = -109588726272418061L;
	private List<T> rows;				// list result of this page
	private long pageNumber;				// page number
	private int pageSize;				// result amount of this page
	private Long totalPage;				// total page
	private Long total;				// total row
	
	public Page(List<T> rows,  Long totalRow ,PageFilter queryPage) {
		this.rows = rows;
		this.pageSize = queryPage.getLimit();
		pageNumber=queryPage.getOffset()/queryPage.getLimit()+1;
		
		this.total = totalRow;
		this.totalPage = totalRow/pageSize;
		if(totalRow%pageSize>0){
			this.totalPage=this.totalPage+1;
		}
	}
	
	/**
	 * Constructor.
	 * @param list the list of paginate result
	 * @param pageNumber the page number
	 * @param pageSize the page size
	 * @param totalRow the total row of paginate
	 */
	public Page(List<T> rows, int pageNumber, int pageSize,  Long totalRow) {
		this.rows = rows;
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
		this.total = totalRow;
		this.totalPage = totalRow/pageSize;
		if(totalRow%pageSize>0){
			this.totalPage=this.totalPage+1;
		}
	}
	
	
	
	/**
	 * Return page number.
	 */
	public long getPageNumber() {
		return pageNumber;
	}
	
	/**
	 * Return page size.
	 */
	public int getPageSize() {
		return pageSize;
	}
	
	/**
	 * Return total page.
	 */
	public Long getTotalPage() {
		return totalPage;
	}
	
	/**
	 * Return total row.
	 */
	/**
	 * @return
	 */
	public Long getTotal() {
		return total;
	}
	
	public List<T> getRows() {
		return rows;
	}



	public boolean isFirstPage() {
		return pageNumber == 1;
	}
	
	public boolean isLastPage() {
		return pageNumber >= totalPage;
	}
}


